from m5stack import * from m5stack_ui import * from uiflow import * screen = M5Screen() screen.clean_screen() screen.set_screen_bg_color(0x000000) value = None adjDice1 = None numberOfDice = None adjDice2 = None glitches = None armorAmount = None phsyDmgAmount = None stunDmgAmount = None successes = None penalty = None sixes = None penaltyStun = None i = None random2 = None diceList = None stats = M5Btn(text='STATS', x=20, y=24, w=280, h=50, bg_c=0xFFFFFF, text_c=0x000000, font=FONT_MONT_26, parent=None) dice = M5Btn(text='DICE', x=20, y=95, w=280, h=50, bg_c=0xFFFFFF, text_c=0x000000, font=FONT_MONT_26, parent=None) comms = M5Btn(text='COMMS', x=20, y=165, w=280, h=50, bg_c=0xFFFFFF, text_c=0x000000, font=FONT_MONT_26, parent=None) armor = M5Label('Armor', x=41, y=24, color=0xffffff, font=FONT_MONT_22, parent=None) armorNumber = M5Label('0', x=118, y=25, color=0xffffff, font=FONT_MONT_22, parent=None) subArmor = M5Btn(text='-', x=162, y=15, w=40, h=40, bg_c=0xFFFFFF, text_c=0x000000, font=FONT_MONT_30, parent=None) addArmor = M5Btn(text='+', x=212, y=15, w=40, h=40, bg_c=0xFFFFFF, text_c=0x000000, font=FONT_MONT_30, parent=None) physDmg = M5Label('Physical Damage', x=30, y=66, color=0xffffff, font=FONT_MONT_22, parent=None) physDmgNum = M5Label('0', x=41, y=101, color=0xffffff, font=FONT_MONT_22, parent=None) subPhysDmg = M5Btn(text='-', x=80, y=92, w=40, h=40, bg_c=0xFFFFFF, text_c=0x000000, font=FONT_MONT_30, parent=None) numberDiceSlider = M5Slider(x=60, y=65, w=200, h=12, min=1, max=30, bg_c=0xa0a0a0, color=0x8a08b0, parent=None) addPhysDmg = M5Btn(text='+', x=130, y=92, w=40, h=40, bg_c=0xFFFFFF, text_c=0x000000, font=FONT_MONT_30, parent=None) stunDmg = M5Label('Stun Damage', x=30, y=147, color=0xffffff, font=FONT_MONT_22, parent=None) numberDiceLabel = M5Label('Dice', x=60, y=24, color=0xffffff, font=FONT_MONT_22, parent=None) physPenalty = M5Label('0', x=240, y=99, color=0xe00b0b, font=FONT_MONT_30, parent=None) numDice = M5Label('0', x=220, y=24, color=0xffffff, font=FONT_MONT_26, parent=None) stunDmgNum = M5Label('0', x=41, y=180, color=0xffffff, font=FONT_MONT_22, parent=None) numSuccess = M5Label('0', x=41, y=95, color=0x27ca1f, font=FONT_MONT_48, parent=None) subStunDmg = M5Btn(text='-', x=80, y=175, w=40, h=40, bg_c=0xFFFFFF, text_c=0x000000, font=FONT_MONT_30, parent=None) numSix = M5Label('0', x=138, y=95, color=0x1f57ca, font=FONT_MONT_48, parent=None) addStunDmg = M5Btn(text='+', x=130, y=175, w=40, h=40, bg_c=0xFFFFFF, text_c=0x000000, font=FONT_MONT_30, parent=None) stunPenalty = M5Label('0', x=239, y=180, color=0xe00b0b, font=FONT_MONT_30, parent=None) numGlitch = M5Label('0', x=230, y=95, color=0xe51313, font=FONT_MONT_48, parent=None) rollDice = M5Btn(text='ROLL', x=20, y=165, w=280, h=50, bg_c=0x710c5f, text_c=0xffffff, font=FONT_MONT_26, parent=None) import random from numbers import Number import math def upRange(start, stop, step): while start <= stop: yield start start += abs(step) def downRange(start, stop, step): while start >= stop: yield start start -= abs(step) # This defines the home screen, showing the main buttons def homeScreen(): global value, adjDice1, numberOfDice, adjDice2, glitches, armorAmount, phsyDmgAmount, stunDmgAmount, successes, penalty, sixes, penaltyStun, i, random2, diceList stats.set_hidden(False) stats.set_bg_color(0x663366) dice.set_hidden(False) dice.set_bg_color(0x993399) comms.set_hidden(False) comms.set_bg_color(0xcc33cc) # Defines the Dice Roller screen, shows the slider, buttons, and dice results def diceScreen(): global value, adjDice1, numberOfDice, adjDice2, glitches, armorAmount, phsyDmgAmount, stunDmgAmount, successes, penalty, sixes, penaltyStun, i, random2, diceList numberDiceLabel.set_hidden(False) numDice.set_hidden(False) numSuccess.set_hidden(False) numSix.set_hidden(False) numGlitch.set_hidden(False) rollDice.set_hidden(False) numberDiceSlider.set_hidden(False) physDmgNum.set_text(str(phsyDmgAmount)) stunDmgNum.set_text(str(stunDmgAmount)) # Defines the Stats screen, the damage buttons and values, and any armor def statsScreen(): global value, adjDice1, numberOfDice, adjDice2, glitches, armorAmount, phsyDmgAmount, stunDmgAmount, successes, penalty, sixes, penaltyStun, i, random2, diceList armor.set_hidden(False) armorNumber.set_hidden(False) physDmg.set_hidden(False) physDmgNum.set_hidden(False) physPenalty.set_hidden(False) stunDmg.set_hidden(False) stunDmgNum.set_hidden(False) stunPenalty.set_hidden(False) subArmor.set_hidden(False) addArmor.set_hidden(False) subPhysDmg.set_hidden(False) addPhysDmg.set_hidden(False) subStunDmg.set_hidden(False) addStunDmg.set_hidden(False) armorNumber.set_text(str(armorAmount)) physDmgNum.set_text(str(phsyDmgAmount)) stunDmgNum.set_text(str(stunDmgAmount)) def numberDiceSlider_changed(value): global adjDice1, numberOfDice, adjDice2, glitches, armorAmount, phsyDmgAmount, stunDmgAmount, successes, penalty, sixes, penaltyStun, random2, diceList numberOfDice = numberDiceSlider.get_value() numDice.set_text(str(numberOfDice)) pass numberDiceSlider.changed(numberDiceSlider_changed) def rollDice_pressed(): global adjDice1, numberOfDice, adjDice2, glitches, armorAmount, phsyDmgAmount, stunDmgAmount, successes, penalty, sixes, penaltyStun, random2, diceList power.setVibrationEnable(True) wait(0.2) power.setVibrationEnable(False) glitches = 0 sixes = 0 successes = 0 if numberOfDice != 0: for i in (1 <= float(numberOfDice)) and upRange(1, float(numberOfDice), 1) or downRange(1, float(numberOfDice), 1): random2 = random.randint(1, 6) if random2 == 1: glitches = glitches + 1 if random2 > 4: successes = successes + 1 if random2 == 6: sixes = sixes + 1 numSuccess.set_text(str(successes)) numSix.set_text(str(sixes)) numGlitch.set_text(str(glitches)) numberOfDice = 0 numDice.set_text(str(numberOfDice)) numberDiceSlider.set_value(0) pass rollDice.pressed(rollDice_pressed) def stats_pressed(): global adjDice1, numberOfDice, adjDice2, glitches, armorAmount, phsyDmgAmount, stunDmgAmount, successes, penalty, sixes, penaltyStun, random2, diceList power.setVibrationEnable(True) wait(0.2) power.setVibrationEnable(False) stats.set_hidden(True) dice.set_hidden(True) comms.set_hidden(True) statsScreen() pass stats.pressed(stats_pressed) def dice_pressed(): global adjDice1, numberOfDice, adjDice2, glitches, armorAmount, phsyDmgAmount, stunDmgAmount, successes, penalty, sixes, penaltyStun, random2, diceList power.setVibrationEnable(True) wait(0.2) power.setVibrationEnable(False) stats.set_hidden(True) dice.set_hidden(True) comms.set_hidden(True) diceScreen() pass dice.pressed(dice_pressed) def addArmor_pressed(): global adjDice1, numberOfDice, adjDice2, glitches, armorAmount, phsyDmgAmount, stunDmgAmount, successes, penalty, sixes, penaltyStun, random2, diceList power.setVibrationEnable(True) wait(0.2) power.setVibrationEnable(False) armorAmount = (armorAmount if isinstance(armorAmount, Number) else 0) + 1 armorNumber.set_text(str(armorAmount)) pass addArmor.pressed(addArmor_pressed) def subArmor_pressed(): global adjDice1, numberOfDice, adjDice2, glitches, armorAmount, phsyDmgAmount, stunDmgAmount, successes, penalty, sixes, penaltyStun, random2, diceList power.setVibrationEnable(True) wait(0.2) power.setVibrationEnable(False) armorAmount = (armorAmount if isinstance(armorAmount, Number) else 0) + -1 armorNumber.set_text(str(armorAmount)) pass subArmor.pressed(subArmor_pressed) def subPhysDmg_pressed(): global adjDice1, numberOfDice, adjDice2, glitches, armorAmount, phsyDmgAmount, stunDmgAmount, successes, penalty, sixes, penaltyStun, random2, diceList power.setVibrationEnable(True) wait(0.2) power.setVibrationEnable(False) phsyDmgAmount = (phsyDmgAmount if isinstance(phsyDmgAmount, Number) else 0) + -1 penalty = math.floor(phsyDmgAmount / 3) physDmgNum.set_text(str(phsyDmgAmount)) physPenalty.set_text(str(penalty)) pass subPhysDmg.pressed(subPhysDmg_pressed) def addPhysDmg_pressed(): global adjDice1, numberOfDice, adjDice2, glitches, armorAmount, phsyDmgAmount, stunDmgAmount, successes, penalty, sixes, penaltyStun, random2, diceList power.setVibrationEnable(True) wait(0.2) power.setVibrationEnable(False) phsyDmgAmount = (phsyDmgAmount if isinstance(phsyDmgAmount, Number) else 0) + 1 penalty = math.floor(phsyDmgAmount / 3) physDmgNum.set_text(str(phsyDmgAmount)) physPenalty.set_text(str(penalty)) pass addPhysDmg.pressed(addPhysDmg_pressed) def subStunDmg_pressed(): global adjDice1, numberOfDice, adjDice2, glitches, armorAmount, phsyDmgAmount, stunDmgAmount, successes, penalty, sixes, penaltyStun, random2, diceList power.setVibrationEnable(True) wait(0.2) power.setVibrationEnable(False) stunDmgAmount = (stunDmgAmount if isinstance(stunDmgAmount, Number) else 0) + -1 penaltyStun = math.floor(stunDmgAmount / 3) stunDmgNum.set_text(str(stunDmgAmount)) stunPenalty.set_text(str(penaltyStun)) pass subStunDmg.pressed(subStunDmg_pressed) def addStunDmg_pressed(): global adjDice1, numberOfDice, adjDice2, glitches, armorAmount, phsyDmgAmount, stunDmgAmount, successes, penalty, sixes, penaltyStun, random2, diceList power.setVibrationEnable(True) wait(0.2) power.setVibrationEnable(False) stunDmgAmount = (stunDmgAmount if isinstance(stunDmgAmount, Number) else 0) + 1 penaltyStun = math.floor(stunDmgAmount / 3) stunDmgNum.set_text(str(stunDmgAmount)) stunPenalty.set_text(str(penaltyStun)) pass addStunDmg.pressed(addStunDmg_pressed) def buttonC_wasPressed(): global adjDice1, numberOfDice, adjDice2, glitches, armorAmount, phsyDmgAmount, stunDmgAmount, successes, penalty, sixes, penaltyStun, random2, diceList power.setVibrationEnable(True) wait(0.2) power.setVibrationEnable(False) successes = 0 sixes = 0 glitches = 0 numberOfDice = 0 numSuccess.set_text(str(successes)) numSix.set_text(str(sixes)) numGlitch.set_text(str(glitches)) numDice.set_text(str(numberOfDice)) numberDiceSlider.set_value(0) pass btnC.wasPressed(buttonC_wasPressed) def buttonB_wasPressed(): global adjDice1, numberOfDice, adjDice2, glitches, armorAmount, phsyDmgAmount, stunDmgAmount, successes, penalty, sixes, penaltyStun, random2, diceList power.setVibrationEnable(True) wait(0.2) power.setVibrationEnable(False) armor.set_hidden(True) armorNumber.set_hidden(True) physDmg.set_hidden(True) physDmgNum.set_hidden(True) physPenalty.set_hidden(True) stunDmgNum.set_hidden(True) stunDmg.set_hidden(True) stunPenalty.set_hidden(True) numberDiceLabel.set_hidden(True) numDice.set_hidden(True) numSuccess.set_hidden(True) numSix.set_hidden(True) numGlitch.set_hidden(True) subArmor.set_hidden(True) addArmor.set_hidden(True) subPhysDmg.set_hidden(True) addPhysDmg.set_hidden(True) subStunDmg.set_hidden(True) addStunDmg.set_hidden(True) rollDice.set_hidden(True) numberDiceSlider.set_hidden(True) homeScreen() pass btnB.wasPressed(buttonB_wasPressed) def buttonA_wasPressed(): global adjDice1, numberOfDice, adjDice2, glitches, armorAmount, phsyDmgAmount, stunDmgAmount, successes, penalty, sixes, penaltyStun, random2, diceList power.setVibrationEnable(True) wait(0.2) power.setVibrationEnable(False) penalty = 0 penaltyStun = 0 phsyDmgAmount = 0 stunDmgAmount = 0 armorAmount = 0 physDmgNum.set_text(str(phsyDmgAmount)) physPenalty.set_text(str(penalty)) stunDmgNum.set_text(str(stunDmgAmount)) stunPenalty.set_text(str(penaltyStun)) armorNumber.set_text(str(armorAmount)) pass btnA.wasPressed(buttonA_wasPressed) screen.set_screen_bg_color(0x000000) armor.set_hidden(True) armorNumber.set_hidden(True) physDmg.set_hidden(True) physDmgNum.set_hidden(True) physPenalty.set_hidden(True) stunDmgNum.set_hidden(True) stunDmg.set_hidden(True) stunPenalty.set_hidden(True) numberDiceLabel.set_hidden(True) numDice.set_hidden(True) numSuccess.set_hidden(True) numSix.set_hidden(True) numGlitch.set_hidden(True) subArmor.set_hidden(True) addArmor.set_hidden(True) subPhysDmg.set_hidden(True) addPhysDmg.set_hidden(True) subStunDmg.set_hidden(True) addStunDmg.set_hidden(True) rollDice.set_hidden(True) armorAmount = 0 phsyDmgAmount = 0 penalty = 0 stunDmgAmount = 0 diceList = [] numberDiceSlider.set_hidden(True) homeScreen()